package com.wootion.cims.module.communitymerchant.controller;
import com.wootion.cims.module.communitymerchant.dto.PageQueryMerchant;
import com.wootion.cims.module.communitymerchant.dto.ShopDto;
import com.wootion.cims.module.communitymerchant.excel.ShopExcel;
import com.wootion.cims.module.communitymerchant.service.MerchantService;
import com.wootion.cims.module.systemsetting.dictionary.model.LogAnotion;
import com.wootion.cims.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: LanQiang
 * @Date: 2023/01/03/14:30
 * @Description: 作用xxx
 */
@RestController
@Api(value = "社区商户")
@RequiresAuthentication
@RequestMapping(path = {"/merchant"})
public class MerchantController {
    @Resource
    private MerchantService merchantService;

    /**
     * 社区商户列表查询
     * @param pageQueryMerchant
     * @return
     */
    @PostMapping(path = {"/list"})
    @ApiOperation(value = "社区商户-列表查询", httpMethod = "POST",notes = "{page:1,limit:10}")
    public ResponseResult list(@RequestBody PageQueryMerchant pageQueryMerchant){
        return merchantService.list(pageQueryMerchant);
    }

    /**
     * 新增社区商户
     * @param shopDto
     * @return
     */
    @PostMapping(path = {"/save"})
    @ApiOperation(value = "新增社区商户", httpMethod = "POST",notes = "")
    @LogAnotion(type = "新增",value = "1",incident = "门店信息",prefixContent = "门店名称")
    public ResponseResult save(@RequestBody @Validated ShopDto shopDto){
        return merchantService.save(shopDto);
    }
    /**
     * 修改社区商户
     * @param shopDto
     * @return
     */
    @PostMapping(path = {"/update"})
    @ApiOperation(value = "修改社区商户", httpMethod = "POST",notes = "")
    public ResponseResult update(HttpServletRequest request,@RequestBody @Validated ShopDto shopDto){
        return merchantService.update(request,shopDto);
    }
    /**
     * 根据id查询当前商户信息
     * @param id
     * @return
     */
    @GetMapping(path = "/find")
    @ApiOperation(value = "社区商户-根据id查询", httpMethod = "GET",notes = "不是jso格式,而是K-V结构,例如：id = 1")
    public ResponseResult find(@RequestParam("id")String id){
        return merchantService.find(id);
    }

    /**
     * 批量删除商户信息
     * @param shopDto
     * @return
     */
    @PostMapping(path = "/delete")
    @ApiOperation(value = "删除社区商户", httpMethod = "POST",notes = "{\"ids\":[\"f51085f268972ea31d97c8384659aa16\"]}")
    public ResponseResult batchDelete(@RequestBody ShopDto shopDto, HttpServletRequest request){
        return merchantService.batchDelete(shopDto,request);
    }

    /**
     * 商户列表excel导出
     * @return
     */
    @PostMapping(path = {"/excel"})
    @LogAnotion(type = "导出",value = "1",incident = "门店信息",prefixContent = "执行导出操作")
    @ApiOperation(value = "社区商户-导出功能", httpMethod = "POST",notes = "{'ids':['1','2'],'keyWord':'xx','category':'xx'}")
    public ResponseResult excelMerchant(@RequestBody ShopExcel shopExcel){
        return merchantService.excelMerchant(shopExcel);
    }
}
